<?php
include("code/databaseconnection.php");

include("header.php");
?>

<?php

if($_GET['action']=="delete")
{
	$id=$_GET['id'];
	mysql_query("DELETE FROM participant
 WHERE ID='".$id."'") or die(mysql_error());	
	echo '<font color="#FF0000" size="6" >User id  '.$id.' Deleted</font>';
}
?>
<?php

if($_GET['action']=="edit")
{
	$id=$_GET['id'];
	$rowresult=mysql_query("SELECT * FROM participant WHERE ID='".$id."'  ") or die(mysql_error());
	
		$row=mysql_fetch_array($rowresult);
		$g_title = $row['TITLE'];
		$g_fname = $row['FIRST_NAME'];
		$g_lname = $row['LAST_NAME'];
		$g_Institutiontype= $row['INSTITUTION'];
		$g_Designationtype =  $row['DESIGNATION'];
		// echo $g_id_type = $row['ID_TYPE'];
		// echo $g_id_number = $row['ID_NUMBER'];
		$g_edu_qualification = $row['EDU_QUALIFICATION'];
		$g_email = $row['EMAIL'];
		$g_office_email = $row['OFFICE_EMAIL'];
		$g_Address = $row['ADDRESS'];
		$g_Temporary_Address = $row['TEMPORARY_ADDRESS'];
		$g_office_address= $row['OFFICE_ADDRSS'];
		$g_PhoneNumber = $row['PHONE_NUMBER'];
		$g_office_phone_number =  $row['OFFICE_PHONE_NUMBER'];
		$g_Appointment_year = $row['APPOINTMENT_YEAR'];
		$g_Subjecttype = $row['APPOINTMENT_SUBJECT'];
		$g_divisiontype = $row['DIVISION'];
		$g_zonetype = $row['ZONE'];
		$g_Districttype = $row['DISTRICT'];
		$g_password = $row['PASSWORD'];
		$g_Gender = $row['GENDER'];
		// echo $g_id = $row['ID'];
		
?>		
<link href="../../Workshop/Admin/jsDatePick_ltr.css" rel="stylesheet" type="text/css" />
<form action="participant_manage.php?action=update&id=<?php  echo $id ?>" method="post">
<table width="600" cellspacing="0" cellpadding="0">
 <tr>
      <td width="199">Title:</td>
      <td width="399"><select name="title" style="width: 215px"><option value="Mr">Mr</option><option value="Mrs">Mrs</option></select>		    </td>
    </tr>
    
    
    <tr>
      <td width="199">First Name:</td>
      <td width="399"><input type="text" name="fname" size="30"  value="<?php echo $g_fname; ?>" /></td>
    </tr>
    
    <tr>
    <td>Last Name:</td>
      <td><input type="text" name="Lname" size="30" value="<?php echo  $g_lname; ?>" /></td>
    </tr>
    
   
    <tr>
      <td>Gender</td>
      <td>
      <?php
	  if($g_Gender=='male')
	  {
		 echo '<input type="radio" name="Gender" value="male" checked="checked" />Male <input type="radio" name="Gender" value="female" />	Female';
		 
	  }
		 else
		 {
			 echo '<input type="radio" name="Gender" value="male" />Male <input type="radio" name="Gender" value="female" checked="checked" />	Female';
			 }
	  
	  
	  ?>
	 
      </td>
    </tr>
    
    <tr>
      <td>Phone Number</td>
      <td><input type="text" name="PhoneNumber" size="30" value="<?php echo $g_PhoneNumber; ?>" /></td>
    </tr>
    
    <tr>
      <td>Email</td>
      <td><input type="text" name="email" size="30" value="<?php echo $g_email; ?>" /></td>
    </tr>
    
    <tr>
      <td>Address</td>
      <td><input type="text" name="Address" size="30" value="<?php echo $g_Address; ?>" /></td>
    </tr>
    
    <tr>
      <td>Temporary_Address</td>
      <td><input type="text" name="Temporary_Address" size="30" value="<?php echo  $g_Temporary_Address; ?>"  /></td>
    </tr>
    <tr>
    <td>Institution:</td>
    <td>
    <select name="Institutiontype" style="width: 215px">
    <option value='<?php  $g_Institutiontype ?>' ><?php echo $g_Institutiontype; ?></option>
    <?php
    $result=mysql_query("SELECT * FROM institution ");
	while ($row=mysql_fetch_array($result))
	{
		echo "<option value='".$row['INSTITUTION_NAME']."'>".$row['INSTITUTION_NAME']."</option>";
		
	}
	
    ?>
    </select>
    </td>
  </tr>
    
    <tr>
    <td>Designation</td>
    <td>
    <select name="Designationtype" style="width: 215px" >
    <option value='<?php  $g_Designationtype ?>'><?php echo $g_Designationtype; ?></option>
    <?php
    $result=mysql_query("SELECT * FROM designation ");
	while ($row=mysql_fetch_array($result))
	{
		echo "<option value='".$row['NAME_DESIGNATION']."'>".$row['NAME_DESIGNATION']."</option>";
		
	}
	
    ?>
    </select>
    </td>
  </tr>
  
  
  <tr>
    <td>Edu_Qualification</td>
    <td>
    <select name="edu_qualification" style="width: 215px">
    <option  value='<?php  $g_edu_qualification ?>'><?php  echo $g_edu_qualification; ?></option>
    <?php
    $result=mysql_query("SELECT * FROM edu_qualification ");
	while ($row=mysql_fetch_array($result))
	{
		echo "<option  value='".$row['NAME_EDU_QUALIFICATION']."'>".$row['NAME_EDU_QUALIFICATION']."</option>";
		
	}
	
    ?>
    </select>
    </td>
  </tr>
    
 
 
  <tr>
    <td>Appointment Subject</td>
    <td>
    <select name="Subjecttype" style="width: 215px" >
    <option value='<?php  $g_Subjecttype ?>'><?php  echo $g_Subjecttype; ?></option>
    <?php
    $result=mysql_query("SELECT * FROM appointment_subject ");
	while ($row=mysql_fetch_array($result))
	{
		echo "<option value='".$row['NAME_APPOINTMENT_SUBJECT']."'>".$row['NAME_APPOINTMENT_SUBJECT']."</option>";
		
	}
	
    ?>
    </select>
    </td>
  </tr>
  
  <tr>
      <td width="199">Appointment Year:</td>
      <td width="399"><select name="Appointment_year" style="width: 215px">
      <option value=' <?php $g_Appointment_year ?>'><?php echo $g_Appointment_year; ?></option>
      <option value="1980">1980</option>
      <option value="1981">1981</option>
      <option value="1982">1982</option>
      <option value="1983">1983</option>
      <option value="1984">1984</option>
      <option value="1985">1985</option>
      <option value="1986">1986</option>
      </select>	
    </td>
    </tr>
  
    
     <tr>
    <td>Division</td>
    <td>
    <select name="divisiontype"  style="width: 215px">
    <option value='<?php  $g_divisiontype  ?>'><?php  echo $g_divisiontype; ?></option>
    <?php
    $result=mysql_query("SELECT * FROM division ");
	while ($row=mysql_fetch_array($result))
	{
		echo "<option value='".$row['NAME_DIVISION']."'>".$row['NAME_DIVISION']."</option>";
		
	}
	
    ?>
    </select>
    </td>
  </tr>
  
    <tr>
    <td>Zone</td>
    <td>
    <select name="zonetype"  style="width: 215px">
    <option value='<?php  $g_zonetype ?>'><?php  echo $g_zonetype; ?></option>
    <?php
    $result=mysql_query("SELECT * FROM zone ");
	while ($row=mysql_fetch_array($result))
	{
		echo "<option value='".$row['NAME_ZONE']."'>".$row['NAME_ZONE']."</option>";
		
	}
	
    ?>
    </select>
    </td>
  </tr>
    
    
    <tr>
    <td>District</td>
    <td>
    <select name="Districttype" style="width: 215px" >
    <option value='<?php  $g_Districttype ?>'><?php  echo $g_Districttype; ?></option>
    <?php
    $result=mysql_query("SELECT * FROM district ");
	while ($row=mysql_fetch_array($result))
	{
		echo "<option value='".$row['NAME_DISTRICT']."'>".$row['NAME_DISTRICT']."</option>";
		
	}
	
    ?>
    </select>
    </td>
  </tr>
  <tr>
      <td width="199">Office Email</td>
      <td width="399"><input type="text" name="office_email" size="30" value="<?php echo  $g_office_email; ?>" /></td>
    </tr>
    
    <tr>
    <td>Office Address</td>
      <td><input type="text" name="office_address" size="30" value="<?php echo  $g_office_address; ?>" /></td>
    </tr>
    

    
    <tr>
      <td>Office Phone Number</td>
      <td><input type="text" name="office_phone_number" value="<?php echo  $g_office_phone_number; ?> " size="30" /></td>
    </tr>
    
    
  
  <tr>
    <td></td>
    <td> <input type="submit" name="submit" value="update" ></td>
  </tr>
  
</table>
</form>

<?php
}

if($_GET['action']=="update")
{
	$id=$_GET['id'];
	$g_title=$_POST['title'];
	$g_fname=$_POST['fname'];
	$g_lname=$_POST['Lname'];
	$g_email=$_POST['email'];
	$g_PhoneNumber=$_POST['PhoneNumber'];
	$g_Address=$_POST['Address'];
	$g_Temporary_Address=$_POST['Temporary_Address'];
	$g_Gender=$_POST['Gender'];
	$g_Institutiontype=$_POST['Institutiontype'];
	$g_Designationtype=$_POST['Designationtype'];
	$g_edu_qualification=$_POST['edu_qualification'];
	$g_Subjecttype=$_POST['Subjecttype'];
	$g_Appointment_year=$_POST['Appointment_year'];
	$g_divisiontype=$_POST['divisiontype'];
	$g_zonetype=$_POST['zonetype'];
	$g_Districttype=$_POST['Districttype'];
	$g_office_email=$_POST['office_email'];
	$g_office_address =$_POST['office_address'];
	$g_office_phone_number=$_POST['office_phone_number'];
	 
mysql_query("UPDATE participant SET TITLE='".$g_title."',FIRST_NAME='".$g_fname."',LAST_NAME='".$g_lname."',EMAIL='".$g_email."',PHONE_NUMBER='".$g_PhoneNumber."',TEMPORARY_ADDRESS='".$g_Address."',ADDRESS='".$g_Temporary_Address."',GENDER='".$g_Gender."',INSTITUTION='".$g_Institutiontype."',DESIGNATION='".$g_Designationtype."',EDU_QUALIFICATION='".$g_edu_qualification."',OFFICE_EMAIL='".$g_office_email."',OFFICE_ADDRSS='".$g_office_address."',OFFICE_PHONE_NUMBER='".$g_office_phone_number."',APPOINTMENT_YEAR='".$g_Appointment_year."',APPOINTMENT_SUBJECT='".$g_Subjecttype."',DIVISION='".$g_divisiontype."',ZONE='".$g_zonetype."',DISTRICT='".$g_Districttype."'   WHERE ID='".$id."'  ") or die(mysql_error());
	
	echo '<font color="#009900" size="6" >User id  '.$id.' Updated</font>';
}

if($_GET['action']=="")
{
$result=mysql_query("SELECT * FROM participant ");
$total = mysql_num_rows($result);
$i=0;

echo '<table width="600" border="1"> 
<tr><td>TITLE</td>
	<td>FIRST_NAME</td>
    <td>LAST_NAME</td>
    <td>INSTITUTION</td>
    <td>DESIGNATION</td>
    <td>ID_TYPE</td>
    <td>ID_NUMBER</td>
    <td>EDU_QUALIFICATION</td>
    <td>EMAIL</td>
    <td>OFFICE_EMAIL</td>
	<td>ADDRESS</td>
	<td>TEMPORARY_ADDRESS</td>
	<td>OFFICE_ADDRSS</td>
	<td>PHONE_NUMBER/td>
    <td>OFFICE_PHONE_NUMBER</td>
    <td>APPOINTMENT_YEAR</td>
    <td>APPOINTMENT_SUBJECT</td>
    <td>DIVISION</td>
    <td>ZONE</td>
	<td>DISTRICT</td>
    <td>PASSWORD</td>
    <td>GENDER</td>
   
	<td>Edit</td>
	<td>Delete</td>
</tr>';
	while ($i < $total)
	{
		$row=mysql_fetch_array($result);
		$g_title = $row['TITLE'];
		$g_fname = $row['FIRST_NAME'];
		$g_lname = $row['LAST_NAME'];
		$g_Institutiontype= $row['INSTITUTION'];
		$g_Designationtype =  $row['DESIGNATION'];
		$g_id_type = $row['ID_TYPE'];
		$g_id_number = $row['ID_NUMBER'];
		$g_edu_qualification = $row['EDU_QUALIFICATION'];
		$g_email = $row['EMAIL'];
		$g_office_email = $row['OFFICE_EMAIL'];
		$g_Address = $row['ADDRESS'];
		$g_Temporary_Address = $row['TEMPORARY_ADDRESS'];
		$g_office_address= $row['OFFICE_ADDRSS'];
		$g_PhoneNumber = $row['PHONE_NUMBER'];
		$g_office_phone_number =  $row['OFFICE_PHONE_NUMBER'];
		$g_Appointment_year = $row['APPOINTMENT_YEAR'];
		$g_Subjecttype = $row['APPOINTMENT_SUBJECT'];
		$g_divisiontype = $row['DIVISION'];
		$g_zonetype = $row['ZONE'];
		$g_Districttype = $row['DISTRICT'];
		$g_password = $row['PASSWORD'];
		$g_Gender = $row['GENDER'];
		$g_id = $row['ID'];
		
		echo "
		<tr>
	<td>".$g_title."</td>
	<td>".$g_fname."</td>
    <td>".$g_lname."</td>
    <td>".$g_Institutiontype."</td>
    <td>".$g_Designationtype."</td>
    <td>".$g_id_type."</td>
    <td>".$g_id_number."</td>
    <td>".$g_edu_qualification."</td>
    <td>".$g_email."</td>
    <td>".$g_office_email."</td>
	<td>".$g_Address."</td>
    <td>".$g_Temporary_Address."</td>
    <td>".$g_office_address."</td>
    <td>".$g_PhoneNumber."</td>
    <td>".$g_office_phone_number."</td>
    <td>".$g_Appointment_year."</td>
    <td>".$g_Subjecttype."</td>
    <td>".$g_divisiontype."</td>
    <td>".$g_zonetype."</td>
	<td>".$g_Districttype."</td>
	<td>".$g_password."</td>
    <td>".$g_Gender."</td>
   
    
	 <td>
	 <a href='?action=delete&id=".$row['ID']."' >
	 <img src='delete.png' border='0' />
	 </a>
	 </td>
	<td><a href='?action=edit&id=".$row['ID']."' ><img border=0 src='edit.png' /></a>
	</td>
</tr>";
		
		
		//echo "<option value='".$row['name']."'>".$row['name']."</option>";
		$i++;
		
	}
	echo "</table>";
}
	
?>
<?php 
include("fooder.php");
?>